import { onMounted, ref } from 'vue'

const storageKey = 'hz_login_user'
const useRember = (loginForm) => {
    // 是否记住密码
    const rember = ref(true)
    const setLoginInfo = (cacheData) => {
        window.localStorage.setItem(storageKey, JSON.stringify(cacheData || null))
    }
    const getLoginInfo = () => {
        let loginData = window.localStorage.getItem(storageKey)
        return JSON.parse(loginData || null)
    }
    onMounted(() => {
        const loginUser = getLoginInfo()
        console.log('loginUser: ', loginUser);
        if (loginUser) {
            loginForm.password = loginUser.password
            loginForm.username = loginUser.username
        }
    })
    return { rember, setLoginInfo }
}

export default useRember